

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 参考资料 视频链接 运行环境  windows10 Linux CentOS 7 Xshell 7  一、流程控制 1.1 if 判断 基本语法  123456789#写法一if [ 条件判断式 ]; then 程序fi#写法二if [ 条件判断式]   then       程序fi  注意事项：(1) [ 条件判断式 ] ，中括号和条件判断式之间 必须 有空格 (2) if 后要">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux _ 笔记2 Shell 流程控制 if、case、for、while_ read读取输入 _ 函数的使用 _ cut、sed、awk、sort命令">
<meta property="og:url" content="http://example.com/2022/01/15/Linux%20_%20Shell%E7%AC%94%E8%AE%B02%20Shell%20%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6%20if%E3%80%81case%E3%80%81for%E3%80%81while_%20read%E8%AF%BB%E5%8F%96%E8%BE%93%E5%85%A5%20_%20%E5%87%BD%E6%95%B0%E7%9A%84%E4%BD%BF%E7%94%A8%20_%20cut%E3%80%81sed%E3%80%81awk%E3%80%81sort%E5%91%BD%E4%BB%A4%20+Demo/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 参考资料 视频链接 运行环境  windows10 Linux CentOS 7 Xshell 7  一、流程控制 1.1 if 判断 基本语法  123456789#写法一if [ 条件判断式 ]; then 程序fi#写法二if [ 条件判断式]   then       程序fi  注意事项：(1) [ 条件判断式 ] ，中括号和条件判断式之间 必须 有空格 (2) if 后要">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/fc5b299517aa4626bed390a2c90ce7ab.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/763466e6d9bc4f09a7bd05e0a9fdc260.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c35638aae79646e3bc8925f2fc1d21e4.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/dc23d1237b9648e383e31acca8413fa0.png">
<meta property="article:published_time" content="2022-01-15T07:07:50.000Z">
<meta property="article:modified_time" content="2022-08-22T15:45:58.450Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Linux">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/fc5b299517aa4626bed390a2c90ce7ab.png">
  
  
  
  <title>Linux _ 笔记2 Shell 流程控制 if、case、for、while_ read读取输入 _ 函数的使用 _ cut、sed、awk、sort命令 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Linux _ 笔记2 Shell 流程控制 if、case、for、while_ read读取输入 _ 函数的使用 _ cut、sed、awk、sort命令"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-01-15 15:07" pubdate>
          2022年1月15日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.4k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          54 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Linux _ 笔记2 Shell 流程控制 if、case、for、while_ read读取输入 _ 函数的使用 _ cut、sed、awk、sort命令</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><hr>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1hW41167NW?p=14">视频链接</a></p>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>windows10</li>
<li>Linux CentOS 7</li>
<li>Xshell 7</li>
</ul>
<h1 id="一、流程控制"><a href="#一、流程控制" class="headerlink" title="一、流程控制"></a>一、流程控制</h1><hr>
<h2 id="1-1-if-判断"><a href="#1-1-if-判断" class="headerlink" title="1.1 if 判断"></a>1.1 if 判断</h2><ol>
<li>基本语法</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">写法一</span><br>if [ 条件判断式 ]; then<br> 程序<br>fi<br><span class="hljs-meta prompt_">#</span><span class="language-bash">写法二</span><br>if [ 条件判断式]<br>   then<br>       程序<br>fi<br></code></pre></td></tr></table></figure>

<p>注意事项：(1) [ 条件判断式 ] ，中括号和条件判断式之间 <strong>必须</strong> 有空格 (2) if 后要有空格</p>
<ol start="2">
<li>案例</li>
</ol>
<p>输入数字，判断是否大于0，大于0则输出true，小于或等于0则输出false</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">!/bin/bash</span><br>if [ $1 -gt 0 ]<br>then<br>        echo true <br>elif [ $1 -le 0 ] <br>then        <br>        echo false<br>fi<br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/d57afac94aff49c5a5584049de6359d4.png#">https://img-blog.csdnimg.cn/d57afac94aff49c5a5584049de6359d4.png#</a> &#x3D;50%x)</p>
<h2 id="1-2-case-语句"><a href="#1-2-case-语句" class="headerlink" title="1.2 case 语句"></a>1.2 case 语句</h2><ol>
<li>基本语法</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs shell">case $变量名 in <br>  &quot;值1&quot;)<br>  	如果变量的值等于值1，则执行程序1<br>  	...<br>  	;;<br>  &quot;值2&quot;)<br>  	如果变量的值等于值2，则执行程序2<br>  	...<br>  	;;<br>  ...省略其他分支<br>   *)<br>    如果变量的值都不是以上的值，则执行此程序<br>    ;;<br>esac<br></code></pre></td></tr></table></figure>

<p>注意事项：</p>
<ul>
<li>case 行尾必须为单词 “in” ，每一个模式匹配必须以右括号 “)” 结束。</li>
<li>双分号 “;;” 表示命令序列结束，相当于 java 中的break。</li>
<li>最后的 “*)” 表示默认模式，相当于java中的default。</li>
</ul>
<ol start="2">
<li>案例</li>
</ol>
<p>输入用户名和密码，如果不对则提示错误的信息</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">!/bin/bash</span><br>if [ $# -eq 2 ]<br>then<br>        # 判断用户名是否正确 <br>        case $1 in  <br>        &quot;uni&quot;)<br>                echo &#x27;用户名正确!&#x27; <br>                ;;<br>        *)<br>                echo &#x27;用户名错误.&#x27;<br>                ;;<br>        esac<br>        # 判断密码是否正确 <br>        case $2 in <br>        &quot;123&quot;)<br>                echo &#x27;密码正确!&#x27;<br>                ;;<br>        *)<br>                echo &#x27;密码错误!&#x27;<br>                ;;<br>        esac<br>elif [ $# -ne 2 ];<br>then<br>        echo &#x27;输入参数有误，请输入用户名和密码&#x27;<br>fi<br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/ac364c984bd0464797e59510764ae4c4.png#">https://img-blog.csdnimg.cn/ac364c984bd0464797e59510764ae4c4.png#</a> &#x3D;50%x)</p>
<h2 id="1-3-for-循环"><a href="#1-3-for-循环" class="headerlink" title="1.3 for 循环"></a>1.3 for 循环</h2><ol>
<li>基本语法1</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell">for (( 初始值;循环控制条件;变量变化 ))<br>	do<br>		程序<br>	done<br></code></pre></td></tr></table></figure>

<ol start="2">
<li>案例</li>
</ol>
<ul>
<li>计算 1+2+3…+100的值</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">!/bin/bash</span><br>sum=0 <br>for(( i=1;i&lt;=100;i++))<br>	do          <br>        sum=$[$sum+$i]<br>	done        <br>            <br>echo $sum  <br></code></pre></td></tr></table></figure>

<p>运行结果：5050</p>
<ol start="3">
<li>基本语法2</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell">for 变量 in 值1 值2 值3...<br>	do <br>		程序<br>	done<br></code></pre></td></tr></table></figure>

<ol start="4">
<li>案例</li>
</ol>
<p>对输入的参数求和</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">!/bin/bash</span><br>sum=0<br>for x in $*<br>    do<br>        sum=$[$sum+$x]<br>    done<br>echo $sum<br></code></pre></td></tr></table></figure>

<p>注意：遍历 <code>&quot;$*&quot;</code> 时候只会遍历一次，而遍历 <code>&quot;$@&quot;</code> 则会遍历每一个输入参数</p>
<h2 id="1-4-while-循环"><a href="#1-4-while-循环" class="headerlink" title="1.4 while 循环"></a>1.4 while 循环</h2><ol>
<li>基本语法</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell">while [ 条件表达式 ]<br>	do <br>		程序<br>	done<br></code></pre></td></tr></table></figure>

<ol start="2">
<li>案例</li>
</ol>
<p>计算1+2+3…+100的结果</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">!/bin/bash</span><br>sum=0 <br>i=1<br>while [ $i -le 100 ]<br>do          <br>        sum=$[$sum + $i]<br>        i=$[$i + 1] <br>done       <br>echo $sum<br></code></pre></td></tr></table></figure>

<h1 id="二、-read-读取控制台输入"><a href="#二、-read-读取控制台输入" class="headerlink" title="二、 read 读取控制台输入"></a>二、 read 读取控制台输入</h1><hr>
<ol>
<li>基本语法</li>
</ol>
<p><code>read(选项)(参数)</code></p>
<ul>
<li>选项<ul>
<li>-p ：指定读取值时候的提示符</li>
<li>-t ：指定读取值时等待的时间（秒）</li>
</ul>
</li>
<li>参数<ul>
<li>变量：指定读取值的变量名</li>
</ul>
</li>
</ul>
<ol start="2">
<li>案例</li>
</ol>
<p>提示5秒内，读取控制台的输入用户名</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">!/bin/bash</span><br>read -t 5 -p &quot;请在5秒内输入用户名: &quot; NAME<br>echo $NAME<br></code></pre></td></tr></table></figure>

<h1 id="三、函数"><a href="#三、函数" class="headerlink" title="三、函数"></a>三、函数</h1><hr>
<h2 id="3-1-系统函数"><a href="#3-1-系统函数" class="headerlink" title="3.1 系统函数"></a>3.1 系统函数</h2><h3 id="basename-函数"><a href="#basename-函数" class="headerlink" title="basename 函数"></a>basename 函数</h3><p><strong>基本语法：</strong> <code>basename [string / pathname] [suffix] </code></p>
<p><strong>功能描述：</strong> 删掉所有的后缀包括最后一个 （’&#x2F;‘）字符，然后打印字符串</p>
<p><strong>选项说明：</strong> <code>suffix </code> 为后缀，若被指定， <code>basename</code>会将<code>pathname</code> 或 <code>string </code>中的 suffix 去掉</p>
<p><strong>案例</strong>：截取当前脚本去掉后缀后的的名称</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">basename ./uni.sh .sh<br></code></pre></td></tr></table></figure>



<h3 id="dirname-函数"><a href="#dirname-函数" class="headerlink" title="dirname 函数"></a>dirname 函数</h3><p><strong>基本语法：</strong> <code>dirname [string / pathname] [suffix] </code></p>
<p><strong>功能描述：</strong> 从给定的包含绝对路径的文件名中去除文件名（非目录的部分），然后返回剩下的路径（目录的部分）</p>
<p><strong>案例：</strong> 获取 <code>uni.sh</code>的文件路径</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">dirname /home/s0125/uni.sh<br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/9474ebd1f4e249e2932ad1c0fed97046.png#">https://img-blog.csdnimg.cn/9474ebd1f4e249e2932ad1c0fed97046.png#</a> &#x3D;80%x)</p>
<h2 id="3-2-自定义函数"><a href="#3-2-自定义函数" class="headerlink" title="3.2 自定义函数"></a>3.2 自定义函数</h2><p><strong>基本语法：</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs shell">[ function ] funname[()]<br>&#123;<br>	函数内容;<br>	[return int;]<br>&#125;<br>funname<br></code></pre></td></tr></table></figure>

<p><strong>使用技巧：</strong></p>
<ul>
<li>在调用函数之前需要先声明函数，shell脚本是逐行运行的，不会像其他语言先编译</li>
<li>函数返回值，只能通过<code>$?</code>系统变量获得，可以显示加 :return 返回，如果不加，将以最后一条命令运行结果，作为返回值，return后跟数组<code>n(0-255)</code></li>
</ul>
<p><strong>案例：</strong> 使用函数计算两个输入参数的和</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">!/bin/bash</span><br>function sum()<br>&#123;<br>        s=0;<br>        s=$[$1+$2]<br>        echo $s<br>&#125;<br>read -p &quot;输入数字a: &quot; a<br>read -p &quot;输入数字b: &quot; b<br>sum $a $b<br></code></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/95fe5ce8168744fe8e155d0a01b9927f.png#">https://img-blog.csdnimg.cn/95fe5ce8168744fe8e155d0a01b9927f.png#</a> &#x3D;50%x)</p>
<h1 id="四、-Shell-工具"><a href="#四、-Shell-工具" class="headerlink" title="四、*Shell 工具"></a>四、*Shell 工具</h1><hr>
<h2 id="4-1-cut"><a href="#4-1-cut" class="headerlink" title="4.1 cut"></a>4.1 cut</h2><p><strong>基本语法：</strong> <code>cut [选项参数] filename</code></p>
<p><strong>功能描述：</strong> 在文件中负责剪切数据，该命令从文件的每一行剪切字节、字符和字段并将这些字节、字符和字段输出。</p>
<p><strong>参数说明：</strong></p>
<table>
<thead>
<tr>
<th>选项参数</th>
<th>作用描述</th>
</tr>
</thead>
<tbody><tr>
<td>-f</td>
<td>列号，提取第几列</td>
</tr>
<tr>
<td>-d</td>
<td>分隔符，按照指定分隔符分割列</td>
</tr>
</tbody></table>
<p><strong>案例：</strong> 以空格剪切测试的文本</p>
<p>测试的文本内容：</p>
<p><code>test.txt</code></p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs kotlin">hello world<br><span class="hljs-keyword">this</span>  <span class="hljs-keyword">is</span> a test<br>i love  you<br></code></pre></td></tr></table></figure>

<ul>
<li>切割第一列</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/fc5b299517aa4626bed390a2c90ce7ab.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<ul>
<li>切割第二、三列</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/763466e6d9bc4f09a7bd05e0a9fdc260.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<ul>
<li>获取 love 字段</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">cat test.txt | grep love<br><br>cat test.txt | grep love | cut -d &quot; &quot; -f 2<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/c35638aae79646e3bc8925f2fc1d21e4.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<ul>
<li>获取 系统PATH变量的第二个 “:” 开始后的所有路径</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">echo $PATH | cut -d &quot;:&quot; -f 3-<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/dc23d1237b9648e383e31acca8413fa0.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>其中，<code>-f</code>参数后的 <code>3-</code> 表示为从第3列开始到最后一列，而<code>-3</code>则可以表示为前三列</p>
<ul>
<li>切割 <code>ifconfig</code>命令 后打印的 IP地址</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">ifconfig ens33 | grep &quot;inet 1&quot; | cut -d &quot; &quot; -f 10<br></code></pre></td></tr></table></figure>

<h2 id="4-2-sed"><a href="#4-2-sed" class="headerlink" title="4.2 sed"></a>4.2 sed</h2><p><strong>基本语法：</strong> <code>sed [选项参数] &#39;command&#39; filename</code></p>
<p><strong>功能描述：</strong> sed是一种流编辑器，每次处理一行内容。处理时，把当前处理的行存储在临时缓存区中，称为”模式空间“，接着用 sed 命令处理缓冲区的内容，处理完成后，把缓冲区的内容送往屏幕。接着处理下一行，这样不断重复，直到文件末尾。文件内容 <strong>并没有改变</strong>，除非使用重定向存储输出。</p>
<p><strong>选项参数：</strong></p>
<table>
<thead>
<tr>
<th>选项参数</th>
<th>作用描述</th>
</tr>
</thead>
<tbody><tr>
<td>-e</td>
<td>直接在指令列模式上进行sed的动作编辑</td>
</tr>
</tbody></table>
<p><strong>command命令参数：</strong></p>
<table>
<thead>
<tr>
<th>命令</th>
<th>作用描述</th>
</tr>
</thead>
<tbody><tr>
<td>a</td>
<td>新增，a的后面可以接字符串，在下一行出现</td>
</tr>
<tr>
<td>d</td>
<td>删除</td>
</tr>
<tr>
<td>s</td>
<td>查找并替换</td>
</tr>
</tbody></table>
<p><strong>案例：</strong></p>
<p>测试文本 sed.txt</p>
<figure class="highlight autoit"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs autoit">hello world<br>uni likes <span class="hljs-built_in">sleep</span><br><br><span class="hljs-keyword">do</span> you like <span class="hljs-built_in">run</span><br>i like eat rice<br></code></pre></td></tr></table></figure>

<ul>
<li>在 sed.txt 中的第二行下方插入一行内容</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">sed &quot;2a and run&quot; sed.txt<br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/9cd04247d2574149b4840d4ae0c43153.png#">https://img-blog.csdnimg.cn/9cd04247d2574149b4840d4ae0c43153.png#</a> &#x3D;50%x)</p>
<ul>
<li>删除 sed.txt 文件中 包含 like的行</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">sed &#x27;/like/d&#x27; sed.txt<br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/27e931bb73ef4ab8bcacb0acbd3ba8d3.png#">https://img-blog.csdnimg.cn/27e931bb73ef4ab8bcacb0acbd3ba8d3.png#</a> &#x3D;50%x)</p>
<ul>
<li>将 sed.txt 文件中 like 替换成 love</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">sed &#x27;s/like/love/g&#x27; sed.txt<br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/fa4534e89c114203b9345c6aebf28ec1.png#">https://img-blog.csdnimg.cn/fa4534e89c114203b9345c6aebf28ec1.png#</a> &#x3D;50%x)</p>
<p>注：命令中的 g 为 global的缩写，表示全局替换</p>
<ul>
<li>将 sed.txt 文件中的第二行删除并将 like 替换成 love</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">sed -e &#x27;2d&#x27; -e &#x27;s/like/love/g&#x27; sed.txt<br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/4a35c718969e47adbdc12eb5d174e129.png#">https://img-blog.csdnimg.cn/4a35c718969e47adbdc12eb5d174e129.png#</a> &#x3D;80%x)</p>
<h2 id="4-3-awk"><a href="#4-3-awk" class="headerlink" title="4.3 awk"></a>4.3 awk</h2><p><strong>基本语法：</strong> <code>awk [选项参数]  &#39;pattern1 &#123;action1&#125; pattern2 &#123;action2&#125; ...&#39; filename</code></p>
<p><strong>功能描述：</strong> 一个强大的文本分析工具，把文件逐行的读入，以空格为默认的分隔符将每行切片，切开的部分再进行分析处理</p>
<p><strong>参数说明：</strong></p>
<ul>
<li><code>pattern</code> ：表示 AWK 在数据中查找的内容，即匹配模式</li>
<li><code>action</code>： 在找到匹配内容时所执行的一系列命令</li>
</ul>
<p>选项参数（部分）：</p>
<table>
<thead>
<tr>
<th>选项参数</th>
<th>作用描述</th>
</tr>
</thead>
<tbody><tr>
<td>-F</td>
<td>指定输入文件折分隔符</td>
</tr>
<tr>
<td>-v</td>
<td>赋值一个用户定义变量</td>
</tr>
</tbody></table>
<p><strong>案例：</strong></p>
<ul>
<li>准备数据</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell">sudo cp /etc/passwd ./<br><span class="hljs-meta prompt_"># </span><span class="language-bash">赋予读的权限</span><br>sudo chown 用户名:用户名 passwd<br>cat passwd<br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/1c8ae2496b4541ad8742ff1b3227cdf1.png#">https://img-blog.csdnimg.cn/1c8ae2496b4541ad8742ff1b3227cdf1.png#</a> &#x3D;60%x)</p>
<ul>
<li>搜索 <code>passwd</code> 文件以 <code>root</code> 关键字开头的所有行，并输出改行的第七列</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">awk -F &#x27;:&#x27; &#x27;/^root/ &#123;print $7&#125;&#x27; passwd<br></code></pre></td></tr></table></figure>

<p>运行结果：</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk"><span class="hljs-regexp">/bin/</span>bash<br></code></pre></td></tr></table></figure>

<ul>
<li>搜索 <code>passwd</code> 文件以<code>root</code>关键字开头的所有航，并输出该行的第1列和第7列，中间以”, “分割</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">awk -F : &#x27;/^root/ &#123;print $1&quot;,&quot;$7&#125;&#x27; passwd<br></code></pre></td></tr></table></figure>

<p>运行结果：</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">root,<span class="hljs-regexp">/bin/</span>bash<br></code></pre></td></tr></table></figure>

<p>注意：只有匹配了<code>pattern</code>的行才会执行 <code>action</code></p>
<ul>
<li>只显示 <code>passwd</code>文件的第一列和第七列，以逗号分割，且在所有行前面添加列名 user，shell在最后一行添加<code>&quot;uni, /bin/test&quot;</code></li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">awk -F : &#x27;BEGIN&#123;print &quot;user,shell&quot;&#125; &#123;print $1&quot;,&quot;$7&#125; END&#123;print &quot;uni, bin/test&quot;&#125;&#x27; passwd <br></code></pre></td></tr></table></figure>

<p>注意：<code>BEGIN</code> 在所有数据读取行之前执行； <code>END</code>在所有数据执行之后执行</p>
<ul>
<li>将 <code>passwd</code> 文件中的用户 id 增加数值1并输出</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">awk -F : -v i=1 &#x27;&#123;print $3+i&#125;&#x27; passwd<br></code></pre></td></tr></table></figure>



<p><strong>内置变量：</strong></p>
<table>
<thead>
<tr>
<th>变量</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>FILENAME</td>
<td>文件名</td>
</tr>
<tr>
<td>NR</td>
<td>已读的记录数</td>
</tr>
<tr>
<td>NF</td>
<td>浏览记录的域的个数（切割后，列的个数）</td>
</tr>
</tbody></table>
<p><strong>案例：</strong></p>
<ul>
<li>统计 <code>passwd</code> 文件名，每行的括号，每行的列数</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">awk -F : &#x27;&#123;print &quot;filename:&quot; FILENAME &quot;, LineNumber: &quot; NR &quot;,columns: &quot; NF&#125;&#x27; passwd<br></code></pre></td></tr></table></figure>

<p>运行结果：</p>
<figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs less">filename:passwd, LineNumber: 1,<span class="hljs-attribute">columns</span>: <span class="hljs-number">7</span><br><span class="hljs-attribute">filename</span>:passwd, <span class="hljs-attribute">LineNumber</span>: <span class="hljs-number">2</span>,<span class="hljs-attribute">columns</span>: <span class="hljs-number">7</span><br><span class="hljs-attribute">filename</span>:passwd, <span class="hljs-attribute">LineNumber</span>: <span class="hljs-number">3</span>,<span class="hljs-attribute">columns</span>: <span class="hljs-number">7</span><br><span class="hljs-attribute">filename</span>:passwd, <span class="hljs-attribute">LineNumber</span>: <span class="hljs-number">4</span>,<span class="hljs-attribute">columns</span>: <span class="hljs-number">7</span><br>...<br></code></pre></td></tr></table></figure>

<ul>
<li>切割 IP</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">ifconfig ens33 | grep &quot;inet 1&quot; | awk -F &#x27; &#x27; &#x27;&#123;print $2&#125;&#x27;<br></code></pre></td></tr></table></figure>

<ul>
<li>查询 <code>sed.txt</code> 中空行所在的行号</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">awk &#x27;/^$/&#123;print NR&#125;&#x27; sed.txt<br></code></pre></td></tr></table></figure>

<p>其中 <code>^$</code> 表示开头结尾之间没有任何内容，即可用来表示空行</p>
<h2 id="4-4-sort"><a href="#4-4-sort" class="headerlink" title="4.4 sort"></a>4.4 sort</h2><p><strong>基本语法：</strong> <code>sort (选项) (参数)</code></p>
<p><strong>功能描述：</strong> sort 命令在Linux里非常又用，将文件进行排序，并将排序结果标准输出</p>
<p><strong>参数说明：（部分）</strong></p>
<table>
<thead>
<tr>
<th>参数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>-n</td>
<td>依照数值的大小排序</td>
</tr>
<tr>
<td>-r</td>
<td>以相反的顺序来排序</td>
</tr>
<tr>
<td>-t</td>
<td>设置排序时所用的分隔字符</td>
</tr>
<tr>
<td>-k</td>
<td>指定需要排序的列</td>
</tr>
</tbody></table>
<p>参数：指定待排序的文件列表</p>
<p><strong>案例：</strong></p>
<ul>
<li>准备测试数据 sort.txt</li>
</ul>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">a</span>:<span class="hljs-number">40</span>:<span class="hljs-number">5</span>.<span class="hljs-number">4</span><br><span class="hljs-attribute">b</span>:<span class="hljs-number">20</span>:<span class="hljs-number">4</span>.<span class="hljs-number">2</span><br><span class="hljs-attribute">c</span>:<span class="hljs-number">50</span>:<span class="hljs-number">2</span>.<span class="hljs-number">3</span><br><span class="hljs-attribute">d</span>:<span class="hljs-number">10</span>:<span class="hljs-number">3</span>.<span class="hljs-number">5</span><br><span class="hljs-attribute">e</span>:<span class="hljs-number">30</span>:<span class="hljs-number">1</span>.<span class="hljs-number">6</span><br></code></pre></td></tr></table></figure>

<ul>
<li>依照第二列数据递减排序</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">sort -t : -nrk 2 sort.txt<br></code></pre></td></tr></table></figure>

<h1 id="五、Shell命令企业面试真题"><a href="#五、Shell命令企业面试真题" class="headerlink" title="五、Shell命令企业面试真题"></a>五、Shell命令企业面试真题</h1><hr>
<h2 id="5-1-京东"><a href="#5-1-京东" class="headerlink" title="5.1 京东"></a>5.1 京东</h2><p><strong>问题1：</strong> 使用Linux 命令查询 file1中空行所在的行号</p>
<p><strong>回答1：</strong> </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">awk &#x27;/^$/&#123;print NR&#125;&#x27; sed.txt<br></code></pre></td></tr></table></figure>

<p>本题考点：</p>
<p>(1) <code>awk</code>命令的基本语法 <code>awk &#39;pattern1&#123;action1&#125; ... &#39;</code> 当<code>pattern1</code>匹配成功时才执行<code>action1</code></p>
<p>(2) <code>NR</code>是<code>awk</code>命令的内置变量，表示已读的记录数，即当前的行号</p>
<p>(3) 空行的正则表达式方法，<code>^</code>表示以某个符号开头，<code>$</code>表示以某个符号结尾，它们之间为空表示一个空行</p>
<p><strong>问题2：</strong> 给出下面的文件 <code>socre.txt</code>，计算第二和列的和并输出</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs">张三 40<br>李四 50<br>王五 60<br></code></pre></td></tr></table></figure>

<p><strong>回答2:</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">cat score.txt | awk -F &quot; &quot; &#x27;&#123;sum+=$2&#125; END&#123;print sum&#125;&#x27;<br></code></pre></td></tr></table></figure>



<h2 id="5-2-搜狐-amp-和讯网"><a href="#5-2-搜狐-amp-和讯网" class="headerlink" title="5.2 搜狐 &amp; 和讯网"></a>5.2 搜狐 &amp; 和讯网</h2><p><strong>问题：</strong> Shell 脚本里如何检查一个文件是否存在？如果不存在该如何处理？</p>
<p><strong>回答:</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">#</span><span class="language-bash">!/bin/bash</span><br><br>if [ -f file.txt]; then<br>    echo &quot;文件存在.&quot;<br>else<br>    echo &quot;文件不存在!&quot;<br>fi<br></code></pre></td></tr></table></figure>

<h2 id="5-3-新浪"><a href="#5-3-新浪" class="headerlink" title="5.3 新浪"></a>5.3 新浪</h2><p><strong>问题：</strong> 用 Shell 写一个脚本，对文本无序的一列数字排序 </p>
<p><strong>回答:</strong> 可以使用awk命令求和</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">sort -n test.txt | awk &#x27;&#123;a+=$0;print$0&#125; END&#123;print &quot;sum=&quot;a&#125;&#x27;<br></code></pre></td></tr></table></figure>

<h2 id="5-4-金河网络"><a href="#5-4-金河网络" class="headerlink" title="5.4 金河网络"></a>5.4 金河网络</h2><p><strong>问题:</strong> 请用 Shell 脚本写出查找当前文件夹（&#x2F;home）下所有的文件内容中包含有字符 “shen”的文件名称</p>
<p><strong>回答:</strong> </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">grep -r &quot;shen&quot; /home | cut -d &quot;:&quot; -f 1<br></code></pre></td></tr></table></figure>





                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/Linux/" class="category-chain-item">Linux</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Linux/">#Linux</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Linux _ 笔记2 Shell 流程控制 if、case、for、while_ read读取输入 _ 函数的使用 _ cut、sed、awk、sort命令</div>
      <div>http://example.com/2022/01/15/Linux _ Shell笔记2 Shell 流程控制 if、case、for、while_ read读取输入 _ 函数的使用 _ cut、sed、awk、sort命令 +Demo/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年1月15日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/01/15/Hadoop%20_%20%E9%9B%86%E7%BE%A4%E9%85%8D%E7%BD%AE%EF%BC%88%E4%B8%80%EF%BC%89%E4%BD%BF%E7%94%A8Shell%E8%84%9A%E6%9C%AC%E8%A7%A3%E5%86%B3%E5%AE%8C%E5%85%A8%E5%88%86%E5%B8%83%E5%BC%8F%E9%9B%86%E7%BE%A4%E8%8A%82%E7%82%B9%E4%B9%8B%E9%97%B4%E7%9A%84%E6%96%87%E4%BB%B6%E4%BC%A0%E8%BE%93%E9%97%AE%E9%A2%98%20_%20scp%E5%91%BD%E4%BB%A4%20_%20rsync%E5%91%BD%E4%BB%A4/" title="Hadoop _ 集群配置（一）使用Shell脚本解决完全分布式集群节点之间的文件传输问题 _ scp命令 _ rsync命令">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Hadoop _ 集群配置（一）使用Shell脚本解决完全分布式集群节点之间的文件传输问题 _ scp命令 _ rsync命令</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/01/14/MyBatis%20%E7%AC%94%E8%AE%B02%20SQL%E6%98%A0%E5%B0%84XML%E6%96%87%E4%BB%B6%E6%A0%87%E7%AD%BE%20select%E3%80%81insert%E3%80%81update%20_%20XML%E8%8E%B7%E5%8F%96%E5%A4%9A%E4%B8%AA%E5%8F%82%E6%95%B0%20_%20MyBatis%E5%AE%9E%E7%8E%B0%E5%A4%9A%E8%A1%A8%E6%9F%A5%E8%AF%A2%20_%20resultMap%E6%A0%87%E7%AD%BE%E6%98%A0%E5%B0%84/" title="MyBatis 笔记2 SQL映射XML文件标签 select、insert、update _ XML获取多个参数 _ MyBatis实现多表查询 _ resultMap标签映射">
                        <span class="hidden-mobile">MyBatis 笔记2 SQL映射XML文件标签 select、insert、update _ XML获取多个参数 _ MyBatis实现多表查询 _ resultMap标签映射</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
